package util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 专门和robbitmq获取连接
 */
public class ConnectionRabbitMQ {

    public static Connection getConnection() throws Exception{
        // 1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 2.在工厂对象中设置MQ的连接信息(ip,port,username,passwa rd)
        factory.setHost("192.168.106.128");
        factory.setPort(5672);
        factory.setVirtualHost("/lagou");
        factory.setUsername("laosun");
        factory.setPassword("123456");
        // 3.通过工厂获得与mq的连接
        Connection connection = factory.newConnection();
        return connection;
    }

    public static void main(String[] args) throws Exception {
        Connection connection = getConnection();
        System.out.println("获取到的连接是:"+connection);
        connection.close();
    }
}
